<?php

require_once(ROOT . LIBRARY .'/comments.class.inc');
$COMMENTS = new Comments();

if(session::user() && (session::user()->hasRole('MODER_COMMENTS') || session::user()->hasRole('ADMIN')))
{

   switch($action)
   {
      case 1:
      # SWITCH COMMENT TO ON
         if(!empty($id))
         {
            if($COMMENTS->turnOnComment($id)) echo '1';
            else echo '0';
         }
         exit();
         break;


      case 2:
      # SWITCH COMMENT TO OFF
         if(!empty($id))
         {
            if($COMMENTS->turnOffComment($id)) echo '1';
            else echo '0';
            
         }
         exit();
         break;


      case 3:
         if(!empty($id))
         {
            if($COMMENTS->deleteComment($id)) echo '1';
            else echo '0';
         }
         exit();
         break;



      default:
         $data  = $COMMENTS->getModerComments(NULL);
         $SMARTY->assign('data', $data);
         $layout = 'comments.html';
   }
} else
{
   if (session::user())
   {
      $ErrorHandler->setError(
              array(
                  'code' => 'access',
                  'varkey' => 'access_denied'
              )
      );
   }
   $layout = 'login.html';
}